﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NPlot;

namespace Hydra
{

  public partial class Form1 : Form
  {
    Hydra hydra;
    public Form1()
    {
      InitializeComponent();
    }
    // получить индекс
    // j - cтрока, i - столбец
    // 0 <= i <= m, 0<= j <= n
    public int getIdx(int i, int j,int n)
    {
      return (j * (n + 1) + i);
    }
    private void button1_Click(object sender, EventArgs e)
    {
      #region объявление переменных
      // число узлов по времени и координате.
      int n, m;
      n = Convert.ToInt32(textBox1.Text);
      m = Convert.ToInt32(textBox2.Text);
      double h, dt;
      h = Convert.ToDouble(textBox12.Text) / n;
      dt = Convert.ToDouble(textBox11.Text) / m;
      double lambda1, lambda2, ro, mu, nu, k, c;
      lambda1 = Convert.ToDouble(textBox3.Text);
      lambda2 = Convert.ToDouble(textBox4.Text);
      ro = Convert.ToDouble(textBox5.Text);
      mu = Convert.ToDouble(textBox6.Text);
      nu = Convert.ToDouble(textBox9.Text);
      k = Convert.ToDouble(textBox7.Text);
      c = Convert.ToDouble(textBox10.Text);
      double u1w1, u1w2, u2w1, u2w2;
      u1w1 = Convert.ToDouble(textBox13.Text);
      u1w2 = Convert.ToDouble(textBox14.Text);
      u2w1 = Convert.ToDouble(textBox16.Text);
      u2w2 = Convert.ToDouble(textBox15.Text);
      #endregion

      // создание объекта, заполнение полей, решение задачи
      hydra = new Hydra();
      if (radioButton3.Checked)
      {
        hydra.hydraConstr(n, m, Convert.ToDouble(textBox11.Text), Convert.ToDouble(textBox12.Text)
          , lambda1, lambda2, ro, mu, nu, k, c);
        hydra.hydraSetFreq(u1w1, u1w2, u2w1, u2w2);
        hydra.useBoundarys();
        hydra.solve();
      }
      if (radioButton4.Checked)
      {
        hydra.hydraConstr(n, m, Convert.ToDouble(textBox11.Text), Convert.ToDouble(textBox12.Text)
          , lambda1, lambda2, ro, mu, nu, k, c);
        hydra.hydraSetFreq(u1w1, u1w2, u2w1, u2w2);
        hydra.useBoundarys();
        hydra.solve2gu();
      }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
      plotSurface2D1.Clear();
      int line = Convert.ToInt32(textBox8.Text);
      double[] absciss = new double[hydra.n + 1];
      double[] ordinate = new double[hydra.n + 1];
      if (radioButton1.Checked)
      {
        for (int i = 0; i < hydra.n + 1; i++)
        {
          int idx = hydra.getIdx(i, line, hydra.n);
          ordinate[i] = hydra.u1[idx];
          absciss[i] = hydra.h * i;
        }
      }
      if (radioButton2.Checked)
      {
        for (int i = 0; i < hydra.n + 1; i++)
        {
          int idx = hydra.getIdx(i, line, hydra.n);
          ordinate[i] = hydra.u2[idx];
          absciss[i] = hydra.h * i;
        }
      }
      LinePlot lp2 = new LinePlot();
      lp2.OrdinateData = ordinate;
      lp2.AbscissaData = absciss;
      lp2.Pen = new Pen(Color.Red, 1.0f);
      plotSurface2D1.Add(lp2);
      this.plotSurface2D1.Refresh();
    }

  }
}
